#include <iostream>
#include <stack>
#include <string>
using namespace std;

class Solution {
public:
    bool isValid(string s)
    {
        if (s.empty())
            return true;
        stack<char> stack_data;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '(' || s[i] == '{' || s[i] == '[')
                stack_data.push(s[i]);
            else {
                if (stack_data.empty())
                    return false;
                char ch = stack_data.top();
                stack_data.pop();
                if (s[i] == ')' && ch != '(' || s[i] == ']' && ch != '[' || s[i] == '}' && ch != '{')
                    return false;
            }
        }
        if (stack_data.empty())
            return true;
        else 
            return false;
    }
};

int main(int argc, char const* argv[])
{
    Solution temp;
    string s = "()[]{}";
    bool result = temp.isValid(s);
    cout << result;
    s = "()";
    result = temp.isValid(s);
    cout << result;
    s = "(]";
    result = temp.isValid(s);
    cout << result;
    s = "([)]";
    result = temp.isValid(s);
    cout << result;
    s = "{[]}";
    result = temp.isValid(s);
    cout << result;
    result = temp.isValid("");
    cout << result;
    result = temp.isValid("[");
    cout << result;
    result = temp.isValid("]");
    cout << result;
    return 0;
}